package cn.lsh.comparator;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

import java.util.StringTokenizer;

public class HotComment3Comparator extends WritableComparator {

	public HotComment3Comparator() {
		super(Text.class, true);
	}


	@Override
	public int compare(WritableComparable a, WritableComparable b) {
		StringTokenizer sta = new StringTokenizer(a.toString(), "_");
		StringTokenizer stb = new StringTokenizer(b.toString(), "_");
		int i = sta.nextToken().compareTo(stb.nextToken().toString());
		if (i == 0) {
			double ad = Double.parseDouble(sta.nextToken());
			double ab = Double.parseDouble(stb.nextToken());
			return Double.compare(ab, ad);
		}
		return i;
	}
}
